#ifndef __CLIENT_H__
#define __CLIENT_H__

#include "common/status.h"

#include <QObject>
#include <QList>
#include <QMap>

class FakeTcp;
class ClientProtocol;
class ClientConnectionAction;
class ClientChatAction;
class ClientUserAction;
class ClientFriendAction;
class QString;
class QTimer;

class Friend;
class Chat;

namespace Client {

class Client : public QObject {
Q_OBJECT
public:
	Client(const QString& ip, const quint16 port);
	~Client();

	/* Connection */
	void connect(const QString& login, const QString& password);
	void disconnect();

	/* User */
	void changeStatus(Status status);
	void changePassword(const QString& oldPassword, const QString& newPassword);
	void signup(const QString& login, const QString& password);

signals:
	/* Connection */
	void CAccepted(Friend *me);
	void CDenied();

	/* Chat */
	void HFStarted(Chat* _chat);
	void HFSent(Chat* _chat, Friend* _friend, const QString& message);
	void HFExited(Chat* _chat, Friend* _friend);
	void HFTerminated(Chat* _chat);
	void HFEntered(Chat* _chat, Friend* _friend);

	/* User */
	void UFFriendStatusChanged(Friend* _friend, QList<int> chats);
	void UFFriendsList(QList<Friend *> friends);

	/* Friend */
	void FFInvitation(const QString &login);
	void FFAddition(Friend *_friend);
	void FFDenial(const QString &login);
	void FFRemoval(Friend *_friend, QList<int> chats);
	
public slots:
	void removeFriend(Friend *friend_);
	void startChat(int id);
	void quitChat(Chat *chat);
	void inviteChat(Chat* chat, int friendId);
	void inviteFriend(const QString &friendLogin);
	void acceptInvitation(const QString &friendLogin);
	void denyInvitation(const QString &friendLogin);
	void sendKeepAlive();
	void cancelConnection();

private slots:
	void newOutcomingMessage(const QString &message,Chat *chat);
	void action();

private:

	void connectionAction(ClientConnectionAction* cca);
	void chatAction(ClientChatAction* cha);
	void userAction(ClientUserAction* cua);
	void friendAction(ClientFriendAction* cfa);

	QMap<int, Chat*> chats;
	QMultiMap<int, int> friendChat;
	QTimer *keepAliveTimer;
	FakeTcp* socket;
	ClientProtocol* clientprotocol;
};

}

#endif

